﻿using System.Web;
using Bintje;

/// <summary>
/// Summary description for AppUser
/// </summary>
public class AppUser
{
    public AppUser()
    {
        //
        // TODO: Add constructor logic here
        //
    }
    /// <summary>
    /// to get the id of Current user
    /// </summary>
    /// <returns></returns>
    public static int currUser()
    {
        if (HttpContext.Current.Session["UserId"] != null)
        {
            return (int)HttpContext.Current.Session["UserId"];
        }
        return 0;
    }

    /// <summary>
    /// Get username by Id
    /// </summary>
    /// <param name="Id"></param>
    /// <returns></returns>
    public static string getUsernameById(int Id)
    {
        string UserName = "";
        if (Id != null && Id > 0)
        {   
            /*
            dbTrailInfoDataContext dbo = BL.dbTrail;
            var user = (from u in dbo.UserDetails
                        where u.ID == Id
                        select new { u.username, u.FirstName, u.LastName }).ToArray();
            if (user.Length > 0)
            {
                //if (user[0].FirstName != null && user[0].FirstName != "")
                //{
                //    UserName = user[0].FirstName;
                //}
                UserName = user[0].username;
            }
            */
            Bintje.bintje.imageoSession session = HttpContext.Current.Session["Session"] as Bintje.bintje.imageoSession;
            if (null != session)
            {
                User user = new User(session);
                if (user.LoadDetails())
                {
                    UserName = user.NickName;
                }
            }
        }
        return UserName;
    }
}
